<?php
    $table = $this->inflect($this->table)->toPhrase(Mz_Inflector::UC_FIRST);
    $pk = $this->primary;
    $this->headTitle($table);
    $this->headLink(array(
        'rel' => 'stylesheet',
        'media' => 'screen',
        'href' => $this->resource('css/crud.css'),
    ));
?>
<?php if (!$this->layout()->getMvcInstance() || !$this->layout()->isEnabled()) echo $this->render('_partials/head.phtml'); ?>

<div id="crud-nav">
    <a href="<?php echo $this->url(array('action' => 'create', 'id' => null)) ?>">
        New <?php echo $this->inflect($table)->singularize() ?>
    </a>
    <a href="<?php echo $this->url(array('action' => 'index', 'controller' => 'index', 'module' => 'crud'), null, true) ?>">
        Return to table list
    </a>
</div>

<?php if (!empty($this->messages)) : ?>
<div id="crud-messages">
    <p>
    <?php echo implode("</p>\n<p>", $this->messages); ?>
    </p>
</div>
<?php endif; ?>

<div class="crud-box">
    <div class="crud-box-head"><h4>Listing contents of table <?php echo $table ?></h4></div>
    <div class="crud-box-body clearfix">

        <table class="db-table" cellspacing="0">
            <tr>
<?php foreach ($this->headers as $header) : ?>
                <th><?php echo $this->sortLink($header) ?></th>
<?php endforeach ?>
                <th colspan="3">Actions</th>
            </tr>
<?php if (!count($this->data)) : ?>
            <tr>
                <td colspan="<?php echo count($this->headers)+3 ?>">This table is empty.</td>
            </tr>
<?php else : $rowNo = 0; ?>

<?php    foreach( $this->data as $row ) : ?>
            <tr<?php echo ++$rowNo % 2 == 0 ? ' class="even"' : null ?>>
<?php        foreach( $row as $col=>$value ) : ?>
                <td<?= $col == $this->sort ? ' class="sorted"' : null ?>><?php echo $this->truncate($value, 20) ?></td>
<?php        endforeach ?>
                <td><a href="<?php echo $this->pkLink($pk, $row, 'read') ?>">Show</a></td>
                <td><a href="<?php echo $this->pkLink($pk, $row, 'update') ?>">Edit</a></td>
                <td><a href="<?php echo $this->pkLink($pk, $row, 'delete') ?>">Delete</a></td>
            </tr>
<?php    endforeach ?>
<?php endif ?>
        </table>
<?php echo $this->paginationControl($this->data, 'elastic', '_partials/pagination_control.phtml') ?>
    </div>
</div>
<!-- View: $Id -->

<?php if (!$this->layout()->getMvcInstance() || !$this->layout()->isEnabled()) echo $this->render('_partials/foot.phtml'); ?>